<template>
  <div align="center">
    <h1>登录</h1>
    <p>账号：<input type="text" v-model="from.name"></p>
    <p>密码：<input type="password" v-model="from.password"></p>
    <p>
      <button @click="Login">登录</button>
    </p>
    <br><br><br><br>
    <table border="1" cellspacing="0">
      <tr>
        <td>标题</td>
        <td>内容</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in err">
        <td>{{ i.title }}</td>
        <td>{{ i.content }}</td>
        <td>
          <button @click="router_baidu">查看</button>
        </td>
      </tr>
    </table>

  </div>
</template>

<script>
export default {
  name: "LoginList",
  data() {
    return {
      from: {},
      code: '',
      err: []
    }
  },
  methods: {
    Login() {
      this.axios.get('login/', this.from)
        .then(res => {
          alert(res.data.msg)
          this.code = res.data.code
        })
    },
    Get_News() {
      this.axios.get('journalism/')
        .then(res => {
          console.log(res)
          this.err = res.data
        })
    },
    router_baidu() {
      if (this.code == 200) {
        this.$router.push('https://www.baidu.com/')
      } else {
        alert('您无权访问')
      }
    }
  },
  mounted() {
    this.Get_News()
  }
}
</script>

<style scoped>

</style>
